package a.a;

import a.c.bb;
import a.c.d;
import a.c.e;
import a.c.q;
import a.c.v;
import a.i.h;

import java.util.ArrayList;
import java.util.List;

class cb
{
  private bb a;
  private v[] b;
  private List c;
  private int d;
  private int[] e;
  private int[] f;
  private int[] g;
  private int h;
  private h i;
  private static final boolean j = false;
  
  public int a(q paramq, int[] paramArrayOfInt1, int[] paramArrayOfInt2, long paramLong)
  {
    int i3 = m.b;
    boolean bool = m.a;
    long l = System.currentTimeMillis();
    this.b = new v[paramq.j()];
    this.a = new bb();
    this.e = paramArrayOfInt1;
    this.f = paramArrayOfInt2;
    this.g = new int[paramq.j()];
    this.h = 0;
    this.i = new h(this.b.length);
    this.c = new ArrayList(paramq.j() * 2);
    this.d = 0;
    e locale = paramq.p();
    int k = locale.f();
    this.i.b(locale);
    this.b[k] = this.a.a(locale);
    do
    {
      do
      {
        if (this.i.g()) {
          break;
        }
        if (i3 != 0) {
          break label208;
        }
        if (System.currentTimeMillis() - l >= paramLong) {
          break;
        }
        b();
      } while (this.a.size() + this.d >= paramq.j());
      a();
    } while ((i3 == 0) && (i3 == 0) && (!bool));
    label208:
    int m = 0;
    int n = this.c.size() - 1;
    do
    {
      do
      {
        if (n < 0) {
          break;
        }
        Object localObject = this.c.get(n);
        if (bool) {
          break label313;
        }
        if ((localObject instanceof Integer))
        {
          m += ((Integer)localObject).intValue();
          if (i3 != 0) {
            continue;
          }
          if (!bool) {}
        }
        else
        {
          this.e[((e)localObject).f()] += m;
        }
        n--;
      } while (!bool);
    } while (i3 != 0);
    n = 2147483647;
    label313:
    int i1 = 0;
    int i2 = this.e.length - 1;
    do
    {
      do
      {
        if (i2 < 0) {
          break;
        }
        n = Math.min(n, this.e[i2]);
        i1 = Math.max(i1, this.e[i2]);
        i2--;
        if (i3 != 0) {
          break label388;
        }
        if (bool) {
          break label386;
        }
      } while (!bool);
    } while (i3 != 0);
    i2 = paramArrayOfInt1.length - 1;
    label386:
    if (i2 >= 0)
    {
      label388:
      paramArrayOfInt1[i2] -= n;
      i2--;
    }
    for (;;)
    {
      if (i3 == 0) {
        if (!bool)
        {
          if (!bool) {
            break;
          }
          this.b = null;
          this.a = null;
          this.c = null;
          this.f = null;
          this.i = null;
          if (i3 != 0) {
            continue;
          }
          this.e = null;
        }
      }
    }
    return i1 - n + 1;
  }
  
  public int a(q paramq, int[] paramArrayOfInt1, int[] paramArrayOfInt2)
  {
    return a(paramq, paramArrayOfInt1, paramArrayOfInt2, 9223372036854775807L);
  }
  
  private void a()
  {
    int i1 = m.b;
    boolean bool = m.a;
    this.h += 1;
    v localv1 = 2147483647;
    int k = 1;
    v localv2 = this.a.f();
    label274:
    label511:
    do
    {
      if (localv2 == null) {
        break;
      }
      localObject = (e)localv2.c();
      int n = 1;
      if (bool) {
        break label607;
      }
      d locald = ((e)localObject).i();
      e locale2;
      v localv3;
      do
      {
        do
        {
          if (locald == null) {
            break;
          }
          locale2 = locald.e();
          if (i1 != 0) {
            break label583;
          }
          if (bool) {
            break label582;
          }
          if (this.b[locale2.f()] == null)
          {
            n = 0;
            localv3 = this.e[localObject.f()] - this.e[locale2.f()] - this.f[locald.d()];
            if (i1 != 0) {
              continue;
            }
            if (localv3 > 0)
            {
              if (i1 == 0) {
                if (localv3 < localv1)
                {
                  localv1 = localv3;
                  this.i.d();
                  this.h += 1;
                  this.i.a(locale2);
                  this.g[locale2.f()] = this.h;
                  k = 1;
                  if (i1 != 0) {
                    continue;
                  }
                  if (!bool) {
                    break label274;
                  }
                }
              }
              if (i1 != 0) {
                continue;
              }
              if (k != 0)
              {
                if (i1 != 0) {
                  continue;
                }
                if (localv3 == localv1)
                {
                  if (i1 != 0) {
                    continue;
                  }
                  if (this.g[locale2.f()] < this.h)
                  {
                    this.i.a(locale2);
                    this.g[locale2.f()] = this.h;
                  }
                }
              }
            }
          }
          locald = locald.j();
        } while (!bool);
      } while (i1 != 0);
      locald = ((e)localObject).h();
      do
      {
        if (locald == null) {
          break;
        }
        locale2 = locald.f();
        if (i1 != 0) {
          break label583;
        }
        if (bool) {
          break label582;
        }
        if (this.b[locale2.f()] == null)
        {
          n = 0;
          localv3 = this.e[locale2.f()] - this.e[localObject.f()] - this.f[locald.d()];
          if (i1 != 0) {
            continue;
          }
          if (localv3 > 0)
          {
            if (i1 == 0) {
              if (localv3 < localv1)
              {
                localv1 = localv3;
                this.i.d();
                this.h += 1;
                this.i.a(locale2);
                this.g[locale2.f()] = this.h;
                k = 0;
                if (i1 != 0) {
                  continue;
                }
                if (!bool) {
                  break label511;
                }
              }
            }
            if (i1 != 0) {
              continue;
            }
            if (k == 0)
            {
              if (i1 != 0) {
                continue;
              }
              if (localv3 == localv1)
              {
                if (i1 != 0) {
                  continue;
                }
                if (this.g[locale2.f()] < this.h)
                {
                  this.i.a(locale2);
                  this.g[locale2.f()] = this.h;
                }
              }
            }
          }
        }
        locald = locald.i();
      } while (!bool);
      if (i1 == 0)
      {
        if ((i1 != 0) || (n != 0))
        {
          this.c.add(localObject);
          this.d += 1;
          this.a.h(this.b[localObject.f()]);
        }
        localv2 = localv2.a();
      }
    } while (!bool);
    label582:
    label583:
    if (i1 == 0) {
      if (i1 != 0) {}
    }
    label607:
    localv2 = k != 0 ? -localv1 : localv1;
    this.c.add(new Integer(localv2));
    Object localObject = this.a.f();
    do
    {
      while (!bool)
      {
        if (localObject == null) {
          break;
        }
        if (bool) {
          break label684;
        }
        this.e[((e)((v)localObject).c()).f()] += localv2;
        localObject = ((v)localObject).a();
      }
    } while (i1 != 0);
    label684:
    int m = this.i.e();
    do
    {
      if (m <= 0) {
        break;
      }
      e locale1 = (e)this.i.b();
      this.b[locale1.f()] = this.a.a(locale1);
      this.i.a(locale1);
      m--;
    } while (!bool);
  }
  
  private void b()
  {
    int i1 = m.b;
    boolean bool = m.a;
    label38:
    label171:
    label304:
    do
    {
      do
      {
        e locale1;
        int m;
        do
        {
          if (this.i.g()) {
            break;
          }
          int k = 1;
          locale1 = (e)this.i.b();
          do
          {
            m = locale1.f();
            d locald = locale1.h();
            e locale2;
            int n;
            do
            {
              do
              {
                if (locald == null) {
                  break label171;
                }
                locale2 = locald.f();
                if (i1 != 0) {
                  break label38;
                }
                if (bool) {
                  break;
                }
                if (this.b[locale2.f()] == null)
                {
                  n = this.e[locale2.f()] - this.e[m] - this.f[locald.d()];
                  if (i1 == 0) {
                    if (n == 0)
                    {
                      this.i.a(locale2);
                      this.b[locale2.f()] = this.a.a(locale2);
                      if (i1 != 0) {
                        continue;
                      }
                      if (!bool) {
                        break label159;
                      }
                    }
                  }
                  k = 0;
                }
                locald = locald.i();
              } while (!bool);
            } while (i1 != 0);
            locald = locale1.i();
            do
            {
              if (locald == null) {
                break label304;
              }
              locale2 = locald.e();
              if (bool) {
                break;
              }
              if (this.b[locale2.f()] == null)
              {
                n = this.e[m] - this.e[locale2.f()] - this.f[locald.d()];
                if (i1 == 0) {
                  if (n == 0)
                  {
                    this.i.a(locale2);
                    this.b[locale2.f()] = this.a.a(locale2);
                    if (i1 != 0) {
                      continue;
                    }
                    if (!bool) {
                      break label292;
                    }
                  }
                }
                k = 0;
              }
              locald = locald.j();
            } while (!bool);
          } while (i1 != 0);
        } while (k == 0);
        this.c.add(locale1);
        this.d += 1;
        this.a.h(this.b[m]);
      } while (i1 != 0);
    } while (!bool);
    label159:
    label292:
    return;
  }
  
  private void a(q paramq)
  {
    int m = m.b;
    boolean bool = m.a;
    int k = this.b.length - 1;
    do
    {
      do
      {
        if (k < 0) {
          break;
        }
        this.b[k] = null;
        k--;
        if ((m == 0) && (bool)) {
          return;
        }
      } while (!bool);
    } while (m != 0);
    if (paramq.j() - a(paramq.p()) != 0) {
      System.err.println("TightTree Check failed! ");
    }
  }
  
  private int a(e parame)
  {
    int m = m.b;
    boolean bool = m.a;
    this.b[parame.f()] = this.a.a(parame);
    int k = 1;
    a.c.m localm = parame.n();
    e locale;
    do
    {
      do
      {
        if (!localm.e()) {
          break;
        }
        locale = localm.a().a(parame);
        if (bool) {
          break label177;
        }
        if (this.b[locale.f()] == null)
        {
          if (m != 0) {
            continue;
          }
          if (this.e[locale.f()] - this.e[parame.f()] - this.f[localm.a().d()] == 0) {
            k += a(locale);
          }
        }
        localm.f();
      } while (!bool);
    } while (m != 0);
    localm = parame.m();
    label177:
    do
    {
      do
      {
        if (!localm.e()) {
          break;
        }
        locale = localm.a().a(parame);
        if (this.b[locale.f()] == null)
        {
          if (m != 0) {
            continue;
          }
          if (this.e[parame.f()] - this.e[locale.f()] - this.f[localm.a().d()] == 0) {
            k += a(locale);
          }
        }
        localm.f();
      } while (!bool);
    } while (m != 0);
    return k;
  }
}



/* Location:           E:\idea\

 * Qualified Name:     a.a.cb

 * JD-Core Version:    0.7.0.1

 */